/*
 *  Copyright (C) 2011 glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * ModuleMenuPanel.java
 *
 * Created on 21/01/2011, 14:32:56
 */

package org.balisunrise.nbpam.components;

import org.balisunrise.application.Module;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.view.BeanTreeView;
import org.openide.nodes.*;

/**
 *
 * @author glauco
 */
public class ModuleMenuPanel extends javax.swing.JPanel
        implements ExplorerManager.Provider{

    private ExplorerManager em;
    private Module module;

    public ModuleMenuPanel(){
        em = new ExplorerManager();
        initComponents();
    }

    /** Creates new form ModuleMenuPanel */
    public ModuleMenuPanel(Module module) {
        this();
        this.setModule(module);
    }

    public Module getModule() {
        return module;
    }

    public void setModule(Module module) {
        this.module = module;
        updateEM();
    }

    private void updateEM(){
        Children children = new ModuleMenuChildren(module);
        Node root = new AbstractNode(children);
        root.setDisplayName(module.getDescription());
        root.setName(module.getName());
        em.setRootContext(root);
        BeanTreeView btv = (BeanTreeView) this.pane;
        btv.setRootVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pane = new BeanTreeView();

        pane.setPreferredSize(new java.awt.Dimension(240, 400));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pane, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pane, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public ExplorerManager getExplorerManager() {
        return em;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane pane;
    // End of variables declaration//GEN-END:variables

}
